﻿using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.Serialization.Formatters.Binary;

namespace NazTek.Extension.Clr4.Test
{
    /// <summary>
    ///This is a test class for MemoryStreamExtensionTest and is intended
    ///to contain all MemoryStreamExtensionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class StreamExtensionTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for ToBase32String
        ///</summary>
        [TestMethod()]
        public void TestToString()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                new SoapFormatter().Serialize(stream, new MockPerson());
                Assert.AreEqual<string>(MockData.SERIAL_BASE32_SOAP_MOCK_PERSON, stream.ToString(Encoding.Default));
            }
        }
        /// <summary>
        ///A test for ToByteArray
        ///</summary>
        [TestMethod()]
        public void TestToByteArray()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                new BinaryFormatter().Serialize(stream, new MockPerson());
                Assert.IsTrue(MockData.SERIAL_DEFAULT_ENCODING_BINARY_MOCK_PERSON_BYTES.Equals<byte>(stream.ToByteArray()));
            }
        }
    }
}
